package cn.edu.scau.cmi.suyaoxing.client;

import cn.edu.scau.cmi.suyaoxing.adapter.*;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;


public class AdapterOfObjectClient extends Application{
   public static void main(String[] args) {
       launch(args);
    }
   private Target vt=new AdapterOfObject();
   @Override
   public void start(Stage primaryStage) {
       GridPane gridpane=new GridPane();
       gridpane.setAlignment(Pos.CENTER);
       gridpane.setHgap(1);
       gridpane.setVgap(1);
       
       Image image=new Image("/res/Adapter_1.jpg");
       ImageView imageview=new ImageView(image);
       imageview.setFitHeight(200);
       imageview.setFitWidth(200);
       
       Button bt1=new Button("转换");
       TextField tf1=new TextField();
       TextField tf2=new TextField();
       Label lb1=new Label("请输入要转换的电压:");
       gridpane.add(imageview, 0, 0,1,4);
       gridpane.add(lb1,5,0,1,1);
       gridpane.add(tf1, 5, 1,1,1);
       gridpane.add(bt1, 6, 1,1,1);
       gridpane.add(tf2, 5, 3,1,1);
       
       bt1.setOnAction(new EventHandler<ActionEvent>() {
           @Override
           public void handle(ActionEvent event) {
        	   tf2.setText(vt.doTarget(Double.parseDouble(tf1.getText())));
           }
       });
       
       Scene scene=new Scene(gridpane,1000,500);
       primaryStage.setTitle("AdapterOfObjectClient");
       primaryStage.setScene(scene);
       primaryStage.show();
    }
}

